<?php
namespace app\agentmobile\controller;

use app\agentmobile\model\Agent;
use app\agentmobile\model\User;
use app\lib\exception\PasswordException;
use app\lib\exception\SuccessMessage;
use app\lib\validate\AgentPasswordValidate;
use app\agentmobile\model\AgentOrder;

class MobileCenter extends Base {
    public function index() {
        $data = User::where("id","=",session('uid'))->with("wxuser")->find();
        $this->assign('info', $data);
        return view();
    }
    // 修改密码
    public function password()
    {
        $data = request()->post();
        if ($data) {
            (new AgentPasswordValidate())->goCheck();
            $res = Agent::update(['pwd' => $data['newPassword']],['id' => session('agentId')]);
            if($res){
                throw new SuccessMessage(['msg' => '密码修改成功']);
            }else{
                throw new PasswordException([['msg' => '密码修改失败']]);
            }
        } else{
            return view();
        }
    }
}